package cn.edu.seu.ssny.controller.web;

import cn.edu.seu.ssny.common.BusinessCollections;
import cn.edu.seu.ssny.common.Constants;
import cn.edu.seu.ssny.common.R;
import cn.edu.seu.ssny.common.utils.DateUtils;
import cn.edu.seu.ssny.controller.BaseController;
import cn.edu.seu.ssny.entity.Project;
import cn.edu.seu.ssny.service.IDeviceDataStdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * 能效分析-历史分析
 */
@RestController
@RequestMapping("/history/analysis")
public class HistoryAnalysisController extends BaseController {
    @Autowired
    private IDeviceDataStdService deviceDataStdService;

    /**
     * 功能描述:
     * <返回制冷机组或者供暖机组的能效(指定项目)(机组能效)
     *
     * @param session
     * @param baseYear
     * @return
     */
    @GetMapping("/cop")
    public R getCop(HttpSession session, @RequestParam("baseYear") String baseYear) {
        Project project = getCurrProject(session);
        List<Date> timeList = DateUtils.getDateList(DateUtils.MODE_YEAR, 3, baseYear);
        List<Double> coolingcop = deviceDataStdService.getCOPByProject(project, timeList, BusinessCollections.machineColdPowerCostTypes, BusinessCollections.machineColdProviderTypes, Constants.CoolingMode, DateUtils.MODE_YEAR);
        List<Double> heatingcop = deviceDataStdService.getCOPByProject(project, timeList, BusinessCollections.machineHotPowerCostTypes, BusinessCollections.machineHotProviderTypes, Constants.HeatingMode, DateUtils.MODE_YEAR);
        List<String> dates = transDateListToDateString(timeList);
        Map<String, Object> data = new HashMap();
        data.put("dates", dates);
        data.put("coolingcop", coolingcop);
        data.put("heatingcop", heatingcop);
        return R.ok().data(data);
    }

    /**
     * 功能描述:
     * <返回制冷能效或者供暖能效(指定项目)(系统能效)
     *
     * @param session
     * @param baseYear
     * @return
     */
    @GetMapping("/scop")
    public R getCops(HttpSession session, @RequestParam("baseYear") String baseYear) {

        Project project = getCurrProject(session);
        List<Date> timeList = DateUtils.getDateList(DateUtils.MODE_YEAR, 3, baseYear);
        List<Double> coolingcop = deviceDataStdService.getCOPByProject(project, timeList, BusinessCollections.powerCostColdTypes, BusinessCollections.providerColdTypes, Constants.CoolingMode, DateUtils.MODE_YEAR);
        List<Double> heatingcop = deviceDataStdService.getCOPByProject(project, timeList, BusinessCollections.powerCostHotTypes, BusinessCollections.providerHotTypes, Constants.HeatingMode, DateUtils.MODE_YEAR);
        List<String> dates = transDateListToDateString(timeList);
        Map<String, Object> data = new HashMap();
        data.put("dates", dates);
        data.put("coolingcop", coolingcop);
        data.put("heatingcop", heatingcop);
        return R.ok().data(data);


    }
}
